import java.util.Scanner;

public class DAY5 {
    public static void main1(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String str1=scanner.nextLine();
        String str2=scanner.nextLine();
        int len=str1.length();
        int n=0;
        for (int i = 0; i <=len; i++) {
            StringBuilder str=new StringBuilder(str1);
            str.insert(i,str2);
            StringBuilder tmp=new StringBuilder(str);
            StringBuilder str5=tmp.reverse();
            if(str.toString().equals(str5.toString())){
                n++;
            }
        }
        System.out.println(n);
    }
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int size=scanner.nextInt();
        int[] array=new int[size];
        for (int i = 0; i < size; i++) {
            array[i]=scanner.nextInt();
        }
        int sum=array[0];
        int max=array[0];
        for (int i = 1; i <size ; i++) {
            sum=max(sum+array[i],array[i]);
            if(sum>=max){
                max=sum;
            }
        }
        System.out.println(max);
    }
    public static int max(int a,int b){
        return (a)>(b)?(a):(b);
    }
}
